package com.qf.forum.controller;

import com.alibaba.fastjson.JSONObject;
import com.qf.base.controller.BaseController;
import com.qf.base.result.R;
import com.qf.forum.dto.ForumDTO;
import com.qf.forum.dto.ForumInsertUserDTO;
import com.qf.forum.dto.ForumUrlDTO;
import com.qf.forum.dto.ForumUserDTO;

import com.qf.forum.service.ForumService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


@RestController
@RequestMapping("/forum")
public class ForumController extends BaseController {
    @Resource
    private ForumService forumService;

    //发布一条论坛信息
    @PostMapping("/insert")
    public R insertforum(@RequestBody ForumDTO forumDTO){
        Long userId = userId();
        boolean result=forumService.insert(userId,forumDTO);
        if (result){
            return R.ok(200,"发布成功");
        }
        return R.error(500,"发布失败");
    }
    //发布一个视频
    @PostMapping("/insertUrl")
    public R insertUrl(MultipartFile file, ForumUrlDTO forumUrlDTO){
        Long userId=userId();

        boolean result=forumService.insert(userId,file,forumUrlDTO);
        if (result){
            return R.ok(200,"发布成功");
        }
        return R.error(500,"发布失败");
    }
    //查看前五条的论坛信息
    @PostMapping("/select")
    public R selectforum(@RequestParam(defaultValue = "1")Integer page,
                         @RequestParam(defaultValue = "5")Integer limit){
        R r = forumService.selectforum(page, limit);
        return r;
    }
    //点进对应标题，根据对应标题查看内容,以及所有的用户评论
    @PostMapping("/selectformuser")
    public R selectforumuser(@RequestBody ForumUserDTO forumUserDTO){
        return forumService.selecforumuser(forumUserDTO);

    }
    //用户进入论坛之后,根据论坛id来进行评论,评论可以评论图片和信息
    @PostMapping("/inserttitle")
    public R insertforumuser(@RequestBody ForumInsertUserDTO forumInsertUserDTO){
        Long userId = userId();
        return forumService.insertforumuser(userId,forumInsertUserDTO);

    }
}
